﻿<UserControl x:Class="Songhay.Silverlight.Controls.MultiSelectDropDown"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">
    <UserControl.Resources>

        <!-- Based on default style for System.Windows.Controls.ListBoxItem -->
        <Style x:Key="ListBoxItemStyle" TargetType="ListBoxItem">
            <Setter Property="Padding" Value="3" />
            <Setter Property="HorizontalContentAlignment" Value="Left" />
            <Setter Property="VerticalContentAlignment" Value="Top" />
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="TabNavigation" Value="Local" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBoxItem">
                        <Grid Background="{TemplateBinding Background}">
                            <vsm:VisualStateManager.VisualStateGroups>
                                <vsm:VisualStateGroup x:Name="CommonStates">
                                    <vsm:VisualState x:Name="Normal" />
                                    <vsm:VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <DoubleAnimation
                                                Storyboard.TargetName="fillColor"
                                                Storyboard.TargetProperty="Opacity"
                                                Duration="0" To=".35"
                                                />
                                        </Storyboard>
                                    </vsm:VisualState>
                                    <vsm:VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <DoubleAnimation
                                                Storyboard.TargetName="contentPresenter"
                                                Storyboard.TargetProperty="Opacity"
                                                Duration="0" To=".55"
                                                />
                                        </Storyboard>
                                    </vsm:VisualState>
                                </vsm:VisualStateGroup>
                                <vsm:VisualStateGroup x:Name="SelectionStates">
                                    <vsm:VisualState x:Name="Unselected" />
                                    <vsm:VisualState x:Name="Selected">
                                        <Storyboard>
                                            <DoubleAnimation
                                                Storyboard.TargetName="fillColor2"
                                                Storyboard.TargetProperty="Opacity"
                                                Duration="0" To=".75"
                                                />
                                        </Storyboard>
                                    </vsm:VisualState>
                                </vsm:VisualStateGroup>
                                <vsm:VisualStateGroup x:Name="FocusStates">
                                    <vsm:VisualState x:Name="Focused">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames
                                                Storyboard.TargetName="FocusVisualElement"
                                                Storyboard.TargetProperty="Visibility"
                                                Duration="0">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </vsm:VisualState>
                                    <vsm:VisualState x:Name="Unfocused"/>
                                </vsm:VisualStateGroup>
                            </vsm:VisualStateManager.VisualStateGroups>
                            <Rectangle x:Name="fillColor"
                                Fill="#FFBADDE9"
                                IsHitTestVisible="False"
                                Opacity="0"
                                RadiusX="1" RadiusY="1"
                                />
                            <Rectangle x:Name="fillColor2"
                                Fill="#FFBADDE9"
                                IsHitTestVisible="False"
                                Opacity="0"
                                RadiusX="1" RadiusY="1"
                                />
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="5*" />
                                    <ColumnDefinition Width="95*"/>
                                </Grid.ColumnDefinitions>
                                <CheckBox
                                    IsChecked="{Binding IsSelected, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
                                    IsHitTestVisible="False">
                                </CheckBox>
                                <ContentPresenter x:Name="contentPresenter"
                                    Grid.Column="1"
                                    Content="{TemplateBinding Content}"
                                    ContentTemplate="{TemplateBinding ContentTemplate}"
                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                    Margin="{TemplateBinding Padding}"
                                    />
                            </Grid>
                            <Rectangle x:Name="FocusVisualElement"
                                RadiusX="1" RadiusY="1"
                                Stroke="#FF6DBDD1"
                                StrokeThickness="1"
                                Visibility="Collapsed"
                                />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </UserControl.Resources>
    <Grid x:Name="LayoutRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <TextBlock x:Name="DropDownSummary"
            Margin="4,0"
            TextTrimming="WordEllipsis"
            />
        <ToggleButton x:Name="DropDownCommand"
            Grid.Column="1"
            Cursor="Hand">
            <Path x:Name="ArrowPath"
                Data="F1 M 301.14,-189.041L 311.57,-189.041L 306.355,-182.942L 301.14,-189.041 Z "
                Margin="4,0"
                HorizontalAlignment="Right"
                Width="16" Height="16"
                Stretch="Uniform">
                <Path.Fill>
                    <SolidColorBrush x:Name="ArrowPathColor" Color="#FF333333"/>
                </Path.Fill>
            </Path>
        </ToggleButton>
        <Popup x:Name="DropDown"
            Grid.ColumnSpan="2" Grid.Row="1"
            IsOpen="{Binding IsChecked, ElementName=DropDownCommand}">
            <ListBox x:Name="InnerListBox"
                ItemContainerStyle="{StaticResource ListBoxItemStyle}"
                SelectionMode="Multiple">
            </ListBox>
        </Popup>
    </Grid>
</UserControl>
